package cate.game.role.show.title;


import cate.common.table.d.GDBlog;
import cate.common.table.show.row.TitleRow;
import cate.game.attr.FightAttr;
import cate.game.role.show.ShowBagTab;
import cate.game.role.show.msg.ModifyTitleResp;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;

import java.util.ArrayList;
import java.util.List;


@NoteClass("称号")
public class RoleTitle extends ShowBagTab<Title> {

    @Override
    public byte getType() {
        return GDBlog.DecorateType.TITLE;
    }

    @Override
    protected Title createItem(int tid, long validTime) {
        return new Title(tid,validTime);
    }

    @Override
    public void onInvalid(List<Integer> expireTids) {
        for (Integer expireTid : expireTids) {
            if (role.getBase().title.tid == expireTid) {
                role.getBase().title.tid = GDBlog.DEFAULT_TITLE;
                role.sendNow(new ModifyTitleResp(role));
                return;
            }
        }
    }

    @JsonIgnore
    public FightAttr getAttr() {
        FightAttr attr = new FightAttr();
        List<Title> titles = new ArrayList<>(this.list);
        for (Title title : titles) {
            TitleRow row = title.getRow(role.getGame());
            if (row != null) {
                attr.add(new FightAttr(row.attrStr));
            }
        }
        return attr;
    }
}
